package gdonly.top.signin.business;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import org.json.JSONException;

import java.util.HashMap;
import java.util.List;

import gdonly.top.signin.R;
import gdonly.top.signin.utils.DatabaseQuery;
import gdonly.top.signin.utils.JsonUtil;
import gdonly.top.signin.widgets.ShowRecordsByStuAdapter;

/**
 * Created by zhuzhuxia on 2017/5/14.
 */
public class QueryRecordsActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private TextView title1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_queryrecords);
        initViews();
    }
    private void initViews(){
        recyclerView = (RecyclerView) findViewById(R.id.records);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        title1 = (TextView) findViewById(R.id.title1);

        Bundle bundle = getIntent().getExtras();
        String userId = bundle.getString("user_id");

        String result = DatabaseQuery.getRecordsByUserId(userId, QueryRecordsActivity.this);
        List<HashMap<String,Object>> data = null;
        try {
            data = JsonUtil.getRecordsByUserId(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if(data.size() == 0){
            title1.setText("检索不到该学生的信息");
        }

        recyclerView.setAdapter(new ShowRecordsByStuAdapter(data, QueryRecordsActivity.this));
    }
}
